var year = document.getElementById("year");
var month = document.getElementById("month");
var day = document.getElementById("day");
var now = new Date();
nowYear = now.getFullYear();
for (var i = 1900; i <= nowYear; i++) {
	var option = document.createElement("option");
	option.setAttribute("value", i);
	option.innerHTML = i;
	year.appendChild(option);
}

/*

for (var i = 0; i <= 31; i++) {
	var option = document.createElement("option");
	option.setAttribute("value", i);
	option.innerHTML = i;
	day.appendChild(option);
}*/

year.onchange = function() {
	month.options[0].selected = true;
	day.options[0].selected = true;
	month.options.length = 1;
	for (var i = 1; i <= 12; i++) {
		var option = document.createElement("option");
		if (i < 10) {
			option.setAttribute("value", i);
			option.innerHTML = "0" + i;
		} else {
			option.setAttribute("value", i);
			option.innerHTML = i;
		}
		month.appendChild(option);
	}
}

month.onchange = function() {
	var year_index = year.selectedIndex;
	var year_text = year.options[year_index].text;
	var month_index = month.selectedIndex;
	var month_text = month.options[month_index].text;
	day.options[0].selected = true;
	day.options.length = 1;
	if (month_text == 2) {
		if ((year_text % 4 === 0 && year_text % 100 !== 0) || year_text % 400 === 0) {
			for (var i = 1; i <= 29; i++) {
				var option = document.createElement("option");
				option.setAttribute("value", i);
				option.innerHTML = i;
				day.appendChild(option);
			}
		} else {
			for (var i = 1; i <= 28; i++) {
				var option = document.createElement("option");
				option.setAttribute("value", i);
				option.innerHTML = i;
				day.appendChild(option);
			}
		}
	} else if (month_text == 4 || month_text == 6 || month_text == 9 || month_text == 11) {
		for (var i = 1; i <= 30; i++) {
			var option = document.createElement("option");
			option.setAttribute("value", i);
			option.innerHTML = i;
			day.appendChild(option);
		}
	} else {
		for (var i = 1; i <= 31; i++) {
			var option = document.createElement("option");
			option.setAttribute("value", i);
			option.innerHTML = i;
			day.appendChild(option);
		}
	}
}